package com.klun.tree;

import com.klun.common.Node;
import com.klun.tree.utils.CreateTree;

public class reverteTree {


    /**
     * 翻转二叉树
     * @param node
     */
    public static void reverte(Node node){
        if(null == node){
            return;
        }
        Node temp = node.left;
        node.left = node.right;
        node.right = temp;
        reverte(node.left);
        reverte(node.right);
    }

    /**
     * 先序遍历
     * @param node
     */
    public static void foreachTree(Node node){
        if(null == node){
            return;
        }
        System.out.print(node.value+"-");
        foreachTree(node.left);
        foreachTree(node.right);
    }

    public static void main(String[] args) {
        Node binaryTree = CreateTree.createBinaryTree();
        foreachTree(binaryTree);
        System.out.println("***********");
        reverte(binaryTree);
        System.out.println("***********");
        foreachTree(binaryTree);
    }

}



